#include<stdbool.h>
#include<ctype.h>

int check(char ch)
{
    if (isdigit(ch))    return ch - '0';
    if (ch == 'A' || ch == 'a')    return 10;
    if (ch == 'B' || ch == 'b')    return 11;
    if (ch == 'C' || ch == 'c')    return 12;
    if (ch == 'D' || ch == 'd')    return 13;
    if (ch == 'E' || ch == 'e')    return 14;
    if (ch == 'F' || ch == 'f')    return 15;
    return 0;
}

int trans(char s[])
{
    bool flag = false;
    for (int i = 0; s[i] != '\0'; i++)
    {
        char ch = s[i];
        if (ch == '-')
        {
            flag = true;
            break;
        }
        if (check(ch))
            break;
    }
    int ret = 0;
    int a = 1;
    int len = strlen(s);
    for (int i = len - 1; i >= 0; i--)
    {
        if (check(s[i]))
        {
            ret += a * check(s[i]);
            a *= 16;
        }
    }
    return flag ? -ret : ret;
}